package com.zzb.myshowme.wiget;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.zzb.myshowme.R;

/**
 * Created by Administrator on 2016/10/28.
 */
public class LoadingDialog extends Dialog {

    private View noticeView;
    private TextView textView;
    private ProgressBar progressBar;

    public LoadingDialog(Context context) {
        super(context, R.style.loading_dialog);
        init(context);
    }

    public LoadingDialog(Context context, int theme) {
        super(context, R.style.loading_dialog);
        init(context);
    }

    public LoadingDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        init(context);
    }

    private void init(Context context) {
        noticeView = LayoutInflater.from(context).inflate(R.layout.loading_progressbar,null);
        textView = (TextView) noticeView.findViewById(R.id.tv_dialog);
        textView.setTextColor(Color.WHITE);
        progressBar = (ProgressBar) noticeView.findViewById(R.id.progressBar1);
        setContentView(noticeView);
    }

    public void show() {
        show("");
    }

    public void show(String text) {
        if (!textView.isShown()) {
            textView.setVisibility(View.VISIBLE);
        }
        textView.setText(text);
        if (!isShowing()) {
            super.show();
        }
    }

    @Override
    public void setCanceledOnTouchOutside(boolean cancel) {
        super.setCanceledOnTouchOutside(true);
    }

    public void showWithNoText() {
        textView.setVisibility(View.GONE);
        if (!isShowing()) {
            super.show();
        }
    }
}
